<?php

class My_database extends CI_Model {

    function __construct()
    {
        parent::__construct();
    }
    
    function get_data()
    {
		$this->db->cache_on();
        $query = $this->db->query('SELECT * FROM entries');
		//$this->db->cache_off();
		foreach ($query->result() as $row)
		{
			$result[] = $row;
		}

		$query = $this->db->query('SELECT * FROM entries where id=1');
		return $result;
    }

	function get_memcache()
	{
		$result = array();
		$sql = "SELECT * FROM entries";
		$key = md5($sql);
		$mem = new Memcache;
		$mem->connect('127.0.0.1', 11211);
		if( ! ($result = $mem->get($key)))
		{
			echo 'Read datas from MySql','<br>';
			$query = $this->db->query($sql);
			foreach ($query->result() as $row)
			{
				$result[] = $row;
			}
			$mem->set($key,$result,0,10);
		}
		else
		{
			echo 'Read datas from memcache','<br>';
		}
		return $result;
		
	}


}
 